// This file is licensed under the Elastic License 2.0. Copyright 2021-present, StarRocks Limited.
//
// Created by grakra on 2021/1/29.
//

#include <gtest/gtest.h>

#include "exprs/vectorized/decimal_cast_expr_test_helper.h"
#include "runtime/primitive_type.h"

namespace starrocks::vectorized {
PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p9s0Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "-761793644894596967.297381278", 9, 0, "", "true"},
                                    {27, 9, "-461280678806068693.412226701", 9, 0, "", "true"},
                                    {27, 9, "439994201611471934.450315435", 9, 0, "", "true"},
                                    {27, 9, "515805506085337076.935530294", 9, 0, "", "true"},
                                    {27, 9, "456340656703626055.126903009", 9, 0, "", "true"},
                                    {27, 9, "-999996965653303549.790982802", 9, 0, "", "true"},
                                    {27, 9, "-999999999999986375.455513495", 9, 0, "", "true"},
                                    {27, 9, "368499637984444486.765735095", 9, 0, "", "true"},
                                    {27, 9, "-999976647588665404.971150407", 9, 0, "", "true"},
                                    {27, 9, "-999999999999999999.135888164", 9, 0, "", "true"},
                                    {27, 9, "-340287821659511487.828221536", 9, 0, "", "true"},
                                    {27, 9, "-999999999999961283.284162576", 9, 0, "", "true"},
                                    {27, 9, "-243264557967066597.883001455", 9, 0, "", "true"},
                                    {27, 9, "-564838211851168391.426405928", 9, 0, "", "true"},
                                    {27, 9, "-999999999999999999.999995968", 9, 0, "", "true"},
                                    {27, 9, "-999999999999999999.980743245", 9, 0, "", "true"},
                                    {27, 9, "-287787781844383117.196892781", 9, 0, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p9s0Normal) {
    CastTestCaseArray test_cases = {{27, 9, "0.010346451", 9, 0, "0", "false"},
                                    {27, 9, "1286.889917574", 9, 0, "1287", "false"},
                                    {27, 9, "0.461423984", 9, 0, "0", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p9s2Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "-867170637813664048.801771456", 9, 2, "", "true"},
                                    {27, 9, "-765226323708894302.222690255", 9, 2, "", "true"},
                                    {27, 9, "-493148306171456532.645128769", 9, 2, "", "true"},
                                    {27, 9, "125456723708845762.266343792", 9, 2, "", "true"},
                                    {27, 9, "-999999999999999999.999485328", 9, 2, "", "true"},
                                    {27, 9, "-982445930812394227.164071522", 9, 2, "", "true"},
                                    {27, 9, "-991923187899258024.460823831", 9, 2, "", "true"},
                                    {27, 9, "-999985765558704723.094848760", 9, 2, "", "true"},
                                    {27, 9, "-999999999999894937.472536647", 9, 2, "", "true"},
                                    {27, 9, "802860594953946882.435025586", 9, 2, "", "true"},
                                    {27, 9, "-998840627536117859.372687995", 9, 2, "", "true"},
                                    {27, 9, "-999999999999885881.981026192", 9, 2, "", "true"},
                                    {27, 9, "-396418908613885390.677357667", 9, 2, "", "true"},
                                    {27, 9, "123646955.499429527", 9, 2, "", "true"},
                                    {27, 9, "-999999999999999999.999999964", 9, 2, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p9s2Normal) {
    CastTestCaseArray test_cases = {{27, 9, "2.77E-7", 9, 2, "0", "false"},
                                    {27, 9, "16.826642205", 9, 2, "16.83", "false"},
                                    {27, 9, "1.548620590", 9, 2, "1.55", "false"},
                                    {27, 9, "0.057524364", 9, 2, "0.06", "false"},
                                    {27, 9, "0.000122994", 9, 2, "0", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p9s9Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "7518329940747792.239946820", 9, 9, "", "true"},
                                    {27, 9, "-999999999999941655.938079821", 9, 9, "", "true"},
                                    {27, 9, "-999999749737066152.526943631", 9, 9, "", "true"},
                                    {27, 9, "-999999999999999999.994062972", 9, 9, "", "true"},
                                    {27, 9, "-668897517356566103.530789481", 9, 9, "", "true"},
                                    {27, 9, "-999999999999999999.987528958", 9, 9, "", "true"},
                                    {27, 9, "-999769483332252487.888683103", 9, 9, "", "true"},
                                    {27, 9, "-339602587232934721.034331833", 9, 9, "", "true"},
                                    {27, 9, "-699516923581038333.550082324", 9, 9, "", "true"},
                                    {27, 9, "17337.209717684", 9, 9, "", "true"},
                                    {27, 9, "-999548119200183631.633437807", 9, 9, "", "true"},
                                    {27, 9, "1077.947695628", 9, 9, "", "true"},
                                    {27, 9, "-999999970210708059.100348709", 9, 9, "", "true"},
                                    {27, 9, "-350581001452255224.387148114", 9, 9, "", "true"},
                                    {27, 9, "-910296577159190744.663371084", 9, 9, "", "true"},
                                    {27, 9, "1158312.965259626", 9, 9, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p9s9Normal) {
    CastTestCaseArray test_cases = {{27, 9, "0.003401051", 9, 9, "0.003401051", "false"},
                                    {27, 9, "0.029229643", 9, 9, "0.029229643", "false"},
                                    {27, 9, "2.038486781", 9, 9, "2.038486781", "false"},
                                    {27, 9, "0.004076438", 9, 9, "0.004076438", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p7s4Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "288057649579167547.896257688", 7, 4, "", "true"},
                                    {27, 9, "468533243502851006.397445250", 7, 4, "", "true"},
                                    {27, 9, "-506396628963119584.455205343", 7, 4, "", "true"},
                                    {27, 9, "-480607499363155104.994243650", 7, 4, "", "true"},
                                    {27, 9, "-999999999989556531.136576724", 7, 4, "", "true"},
                                    {27, 9, "919022334645174552.839831207", 7, 4, "", "true"},
                                    {27, 9, "-999999999999999961.569255493", 7, 4, "", "true"},
                                    {27, 9, "-999999999999999200.708807674", 7, 4, "", "true"},
                                    {27, 9, "27455907537.195033838", 7, 4, "", "true"},
                                    {27, 9, "310015837028897517.227669184", 7, 4, "", "true"},
                                    {27, 9, "34724504387438067.993236369", 7, 4, "", "true"},
                                    {27, 9, "-999999999422689007.356052525", 7, 4, "", "true"},
                                    {27, 9, "-893384442210998070.696136910", 7, 4, "", "true"},
                                    {27, 9, "-999999999997648329.684231580", 7, 4, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal32p7s4Normal) {
    CastTestCaseArray test_cases = {{27, 9, "0.109742267", 7, 4, "0.1097", "false"},
                                    {27, 9, "0.002899567", 7, 4, "0.0029", "false"},
                                    {27, 9, "1E-9", 7, 4, "0", "false"},
                                    {27, 9, "0.002391144", 7, 4, "0.0024", "false"},
                                    {27, 9, "4.728876379", 7, 4, "4.7289", "false"},
                                    {27, 9, "591.342943103", 7, 4, "591.3429", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL32>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p18s0Normal) {
    CastTestCaseArray test_cases = {{27, 9, "-939889591807284565.554007633", 18, 0, "-939889591807284566", "false"},
                                    {27, 9, "-428094851711962698.400207166", 18, 0, "-428094851711962698", "false"},
                                    {27, 9, "-999999998868188514.943470996", 18, 0, "-999999998868188515", "false"},
                                    {27, 9, "-999993281533494844.615728845", 18, 0, "-999993281533494845", "false"},
                                    {27, 9, "4.045226961", 18, 0, "4", "false"},
                                    {27, 9, "0.002959840", 18, 0, "0", "false"},
                                    {27, 9, "0.025250097", 18, 0, "0", "false"},
                                    {27, 9, "0.216112780", 18, 0, "0", "false"},
                                    {27, 9, "-211360145404305049.215605353", 18, 0, "-211360145404305049", "false"},
                                    {27, 9, "0E-9", 18, 0, "0", "false"},
                                    {27, 9, "-999999999999999999.999630379", 18, 0, "-1000000000000000000", "false"},
                                    {27, 9, "0.000173524", 18, 0, "0", "false"},
                                    {27, 9, "-999999923635631586.715503147", 18, 0, "-999999923635631587", "false"},
                                    {27, 9, "-999999999999999999.999999982", 18, 0, "-1000000000000000000", "false"},
                                    {27, 9, "0.059650889", 18, 0, "0", "false"},
                                    {27, 9, "-608635005311893632.769375341", 18, 0, "-608635005311893633", "false"},
                                    {27, 9, "176.009357261", 18, 0, "176", "false"},
                                    {27, 9, "2.965160487", 18, 0, "3", "false"},
                                    {27, 9, "-999998704804247870.435862801", 18, 0, "-999998704804247870", "false"},
                                    {27, 9, "-999999987487328968.355702332", 18, 0, "-999999987487328968", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p18s2Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "-999999999087970768.682074725", 18, 2, "", "true"},
                                    {27, 9, "-839111470501603275.971364833", 18, 2, "", "true"},
                                    {27, 9, "-999999999999999935.209409353", 18, 2, "", "true"},
                                    {27, 9, "-999999999999999999.999988639", 18, 2, "", "true"},
                                    {27, 9, "-999999999999999999.999997942", 18, 2, "", "true"},
                                    {27, 9, "926719711178791318.761552549", 18, 2, "", "true"},
                                    {27, 9, "555185677560826391.737470880", 18, 2, "", "true"},
                                    {27, 9, "-274376651581675006.524087108", 18, 2, "", "true"},
                                    {27, 9, "-999999999999999263.878930754", 18, 2, "", "true"},
                                    {27, 9, "-999999999999999999.994080042", 18, 2, "", "true"},
                                    {27, 9, "-637263599531006785.723340461", 18, 2, "", "true"},
                                    {27, 9, "-999999999999999999.999096814", 18, 2, "", "true"},
                                    {27, 9, "-871744889811170934.499240763", 18, 2, "", "true"},
                                    {27, 9, "-922192930545021033.953009274", 18, 2, "", "true"},
                                    {27, 9, "-539243710141480818.020850717", 18, 2, "", "true"},
                                    {27, 9, "343993370551403648.994131912", 18, 2, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p18s2Normal) {
    CastTestCaseArray test_cases = {{27, 9, "82104978565776236.499001852", 18, 2, "82104978565776236.50", "false"},
                                    {27, 9, "0.038265569", 18, 2, "0.04", "false"},
                                    {27, 9, "14457467672844002.888798884", 18, 2, "14457467672844002.89", "false"},
                                    {27, 9, "5908727848949.027063941", 18, 2, "5908727848949.03", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p18s9Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "-999999999999923711.096714271", 18, 9, "", "true"},
                                    {27, 9, "-891941134451593615.772982829", 18, 9, "", "true"},
                                    {27, 9, "28501200903109.580971482", 18, 9, "", "true"},
                                    {27, 9, "-999999999997980026.428779182", 18, 9, "", "true"},
                                    {27, 9, "-999999998603029258.736946329", 18, 9, "", "true"},
                                    {27, 9, "-521919807193132802.632570055", 18, 9, "", "true"},
                                    {27, 9, "862441737430507008.546566859", 18, 9, "", "true"},
                                    {27, 9, "-999999999999985701.238813025", 18, 9, "", "true"},
                                    {27, 9, "4067696754177200.236037388", 18, 9, "", "true"},
                                    {27, 9, "-88385540319934234.174739014", 18, 9, "", "true"},
                                    {27, 9, "861603976589477135.144040107", 18, 9, "", "true"},
                                    {27, 9, "-999992330457217152.028259188", 18, 9, "", "true"},
                                    {27, 9, "-999999983831302068.292725997", 18, 9, "", "true"},
                                    {27, 9, "-999999999999999999.236694425", 18, 9, "", "true"},
                                    {27, 9, "-999999992143114557.087870189", 18, 9, "", "true"},
                                    {27, 9, "246711935634375582.017729385", 18, 9, "", "true"},
                                    {27, 9, "832343866281036076.802319925", 18, 9, "", "true"},
                                    {27, 9, "364564482913265202.278835103", 18, 9, "", "true"},
                                    {27, 9, "-999999999999999999.999999953", 18, 9, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p18s9Normal) {
    CastTestCaseArray test_cases = {{27, 9, "0.000009056", 18, 9, "0.000009056", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p18s18Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "-720825586109066503.900821343", 18, 18, "", "true"},
                                    {27, 9, "3585654278.942424692", 18, 18, "", "true"},
                                    {27, 9, "-999999999999999999.999968139", 18, 18, "", "true"},
                                    {27, 9, "-999999999999999999.868084417", 18, 18, "", "true"},
                                    {27, 9, "544249628209476198.628198129", 18, 18, "", "true"},
                                    {27, 9, "1281512.248029085", 18, 18, "", "true"},
                                    {27, 9, "-999999995500999818.912255706", 18, 18, "", "true"},
                                    {27, 9, "-811208673006083868.774311576", 18, 18, "", "true"},
                                    {27, 9, "-372553506747088583.924390683", 18, 18, "", "true"},
                                    {27, 9, "-265812272769411950.783949619", 18, 18, "", "true"},
                                    {27, 9, "149811832.229031124", 18, 18, "", "true"},
                                    {27, 9, "694915432149314707.262480550", 18, 18, "", "true"},
                                    {27, 9, "410501.223334472", 18, 18, "", "true"},
                                    {27, 9, "-999999998968097237.368152691", 18, 18, "", "true"},
                                    {27, 9, "237699233676016158.521109202", 18, 18, "", "true"},
                                    {27, 9, "-5251208671976397.910221271", 18, 18, "", "true"},
                                    {27, 9, "945010876491116.810499245", 18, 18, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p18s18Normal) {
    CastTestCaseArray test_cases = {{27, 9, "1E-9", 18, 18, "0.000000001000000000", "false"},
                                    {27, 9, "0.000004524", 18, 18, "0.000004524000000000", "false"},
                                    {27, 9, "0.000205238", 18, 18, "0.000205238000000000", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p15s13Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "-894297339319850392.273388162", 15, 13, "", "true"},
                                    {27, 9, "-999999999999932245.847319421", 15, 13, "", "true"},
                                    {27, 9, "-999998650830864593.694152834", 15, 13, "", "true"},
                                    {27, 9, "-856550754840642245.285657343", 15, 13, "", "true"},
                                    {27, 9, "-999999999999999999.999994915", 15, 13, "", "true"},
                                    {27, 9, "-999999999999790769.712601129", 15, 13, "", "true"},
                                    {27, 9, "17850673.546774223", 15, 13, "", "true"},
                                    {27, 9, "-243998948690429599.795360582", 15, 13, "", "true"},
                                    {27, 9, "-999999999999997493.614799413", 15, 13, "", "true"},
                                    {27, 9, "243718837.738050000", 15, 13, "", "true"},
                                    {27, 9, "56932339.784783169", 15, 13, "", "true"},
                                    {27, 9, "-999991126016405005.050484235", 15, 13, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal64p15s13Normal) {
    CastTestCaseArray test_cases = {{27, 9, "0.457540339", 15, 13, "0.4575403390000", "false"},
                                    {27, 9, "245306.625284238", 15, 13, "245306.6252842380000", "false"},
                                    {27, 9, "0E-9", 15, 13, "0", "false"},
                                    {27, 9, "0.000064730", 15, 13, "0.0000647300000", "false"},
                                    {27, 9, "6.661261897", 15, 13, "6.6612618970000", "false"},
                                    {27, 9, "0.000004887", 15, 13, "0.0000048870000", "false"},
                                    {27, 9, "31.711540558", 15, 13, "31.7115405580000", "false"},
                                    {27, 9, "1556.221515497", 15, 13, "1556.2215154970000", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL64>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal128p38s0Normal) {
    CastTestCaseArray test_cases = {{27, 9, "-278406585388128183.468416297", 38, 0, "-278406585388128183", "false"},
                                    {27, 9, "-772345593876236189.712771765", 38, 0, "-772345593876236190", "false"},
                                    {27, 9, "-138597845043411442.723023429", 38, 0, "-138597845043411443", "false"},
                                    {27, 9, "-999997653994218581.605472232", 38, 0, "-999997653994218582", "false"},
                                    {27, 9, "-999541710694266980.206705651", 38, 0, "-999541710694266980", "false"},
                                    {27, 9, "654651259719433645.059368359", 38, 0, "654651259719433645", "false"},
                                    {27, 9, "7.322774014", 38, 0, "7", "false"},
                                    {27, 9, "-999999662659803853.448420849", 38, 0, "-999999662659803853", "false"},
                                    {27, 9, "-999999999998896942.051669745", 38, 0, "-999999999998896942", "false"},
                                    {27, 9, "-366847966452698649.937585882", 38, 0, "-366847966452698650", "false"},
                                    {27, 9, "658572327063511193.930687737", 38, 0, "658572327063511194", "false"},
                                    {27, 9, "-999999999999999999.999999344", 38, 0, "-1000000000000000000", "false"},
                                    {27, 9, "-47010832289809591.075002912", 38, 0, "-47010832289809591", "false"},
                                    {27, 9, "-999999999999999999.999954127", 38, 0, "-1000000000000000000", "false"},
                                    {27, 9, "885288828187507812.342297541", 38, 0, "885288828187507812", "false"},
                                    {27, 9, "4.007945234", 38, 0, "4", "false"},
                                    {27, 9, "-999986094800137110.938646185", 38, 0, "-999986094800137111", "false"},
                                    {27, 9, "-999999073358509364.772047327", 38, 0, "-999999073358509365", "false"},
                                    {27, 9, "-543693000207862415.057562890", 38, 0, "-543693000207862415", "false"},
                                    {27, 9, "-885501559382766851.862197472", 38, 0, "-885501559382766852", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL128>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal128p38s2Normal) {
    CastTestCaseArray test_cases = {{27, 9, "-999999898013861061.401635767", 38, 2, "-999999898013861061.40", "false"},
                                    {27, 9, "-999999999999999999.999999998", 38, 2, "-1000000000000000000", "false"},
                                    {27, 9, "-503456012261669653.767362741", 38, 2, "-503456012261669653.77", "false"},
                                    {27, 9, "-419538941807976115.997117129", 38, 2, "-419538941807976116", "false"},
                                    {27, 9, "133857702903574688.241197053", 38, 2, "133857702903574688.24", "false"},
                                    {27, 9, "0.009388615", 38, 2, "0.01", "false"},
                                    {27, 9, "-999904108597825646.577553811", 38, 2, "-999904108597825646.58", "false"},
                                    {27, 9, "964890.642184168", 38, 2, "964890.64", "false"},
                                    {27, 9, "12299288933.959735755", 38, 2, "12299288933.96", "false"},
                                    {27, 9, "0.000001742", 38, 2, "0", "false"},
                                    {27, 9, "-530768268312696113.974710811", 38, 2, "-530768268312696113.97", "false"},
                                    {27, 9, "-999999999758639537.111810852", 38, 2, "-999999999758639537.11", "false"},
                                    {27, 9, "-68247334675933568.191457102", 38, 2, "-68247334675933568.19", "false"},
                                    {27, 9, "-999999999997649258.164193652", 38, 2, "-999999999997649258.16", "false"},
                                    {27, 9, "0.051976499", 38, 2, "0.05", "false"},
                                    {27, 9, "0.426618344", 38, 2, "0.43", "false"},
                                    {27, 9, "816345.833478001", 38, 2, "816345.83", "false"},
                                    {27, 9, "2.23E-7", 38, 2, "0", "false"},
                                    {27, 9, "-999999999999994396.520728265", 38, 2, "-999999999999994396.52", "false"},
                                    {27, 9, "829354775.777079610", 38, 2, "829354775.78", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL128>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal128p38s9Normal) {
    CastTestCaseArray test_cases = {
            {27, 9, "-999999999999999777.437842345", 38, 9, "-999999999999999777.437842345", "false"},
            {27, 9, "0.002235649", 38, 9, "0.002235649", "false"},
            {27, 9, "-118490844342015365.798883326", 38, 9, "-118490844342015365.798883326", "false"},
            {27, 9, "15.385185197", 38, 9, "15.385185197", "false"},
            {27, 9, "-999999999999962922.345699419", 38, 9, "-999999999999962922.345699419", "false"},
            {27, 9, "449059561.169496076", 38, 9, "449059561.169496076", "false"},
            {27, 9, "662031803126291354.749933956", 38, 9, "662031803126291354.749933956", "false"},
            {27, 9, "892267994733152094.746725994", 38, 9, "892267994733152094.746725994", "false"},
            {27, 9, "-999999999999999983.588511377", 38, 9, "-999999999999999983.588511377", "false"},
            {27, 9, "-391331144225620264.598733829", 38, 9, "-391331144225620264.598733829", "false"},
            {27, 9, "227580001221295808.984232918", 38, 9, "227580001221295808.984232918", "false"},
            {27, 9, "-583315427763421103.539630583", 38, 9, "-583315427763421103.539630583", "false"},
            {27, 9, "-999999999999999999.996009196", 38, 9, "-999999999999999999.996009196", "false"},
            {27, 9, "-824948100044111054.333564303", 38, 9, "-824948100044111054.333564303", "false"},
            {27, 9, "3684732685570148.305835466", 38, 9, "3684732685570148.305835466", "false"},
            {27, 9, "0.073948763", 38, 9, "0.073948763", "false"},
            {27, 9, "-199903452325974163.606896252", 38, 9, "-199903452325974163.606896252", "false"},
            {27, 9, "-999999999999999999.975234509", 38, 9, "-999999999999999999.975234509", "false"},
            {27, 9, "-486595644903799376.039021945", 38, 9, "-486595644903799376.039021945", "false"},
            {27, 9, "-999999999999975196.065390948", 38, 9, "-999999999999975196.065390948", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL128>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal128p38s13Normal) {
    CastTestCaseArray test_cases = {
            {27, 9, "25685436.437888009", 38, 13, "25685436.4378880090000", "false"},
            {27, 9, "578263503425007803.812608578", 38, 13, "578263503425007803.8126085780000", "false"},
            {27, 9, "9.5E-8", 38, 13, "0.0000000950000", "false"},
            {27, 9, "11491.103471253", 38, 13, "11491.1034712530000", "false"},
            {27, 9, "-999999999999996982.820180423", 38, 13, "-999999999999996982.8201804230000", "false"},
            {27, 9, "-999999946642233275.986259183", 38, 13, "-999999946642233275.9862591830000", "false"},
            {27, 9, "-999768023276955250.872361276", 38, 13, "-999768023276955250.8723612760000", "false"},
            {27, 9, "-816900555727539222.137460740", 38, 13, "-816900555727539222.1374607400000", "false"},
            {27, 9, "797047882432891015.976316521", 38, 13, "797047882432891015.9763165210000", "false"},
            {27, 9, "-999999999999145061.644572619", 38, 13, "-999999999999145061.6445726190000", "false"},
            {27, 9, "1.090485266", 38, 13, "1.0904852660000", "false"},
            {27, 9, "-999998954003166080.098349534", 38, 13, "-999998954003166080.0983495340000", "false"},
            {27, 9, "-113616786820712152.266868437", 38, 13, "-113616786820712152.2668684370000", "false"},
            {27, 9, "-999999999998608673.672149576", 38, 13, "-999999999998608673.6721495760000", "false"},
            {27, 9, "355870321228400251.603009989", 38, 13, "355870321228400251.6030099890000", "false"},
            {27, 9, "114045549.406066101", 38, 13, "114045549.4060661010000", "false"},
            {27, 9, "-999999933641477496.708721656", 38, 13, "-999999933641477496.7087216560000", "false"},
            {27, 9, "450316868231357786.428975181", 38, 13, "450316868231357786.4289751810000", "false"},
            {27, 9, "-686648786464645116.470780544", 38, 13, "-686648786464645116.4707805440000", "false"},
            {27, 9, "3051122082945545.046571006", 38, 13, "3051122082945545.0465710060000", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL128>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal128p38s18Normal) {
    CastTestCaseArray test_cases = {
            {27, 9, "308204948776742418.278494910", 38, 18, "308204948776742418.278494910000000000", "false"},
            {27, 9, "-997864755598185042.443990811", 38, 18, "-997864755598185042.443990811000000000", "false"},
            {27, 9, "-999999999999999999.999995448", 38, 18, "-999999999999999999.999995448000000000", "false"},
            {27, 9, "5866021.939438078", 38, 18, "5866021.939438078000000000", "false"},
            {27, 9, "97442772398587.218904090", 38, 18, "97442772398587.218904090000000000", "false"},
            {27, 9, "992727105559177391.889857186", 38, 18, "992727105559177391.889857186000000000", "false"},
            {27, 9, "-999999999999991983.819586044", 38, 18, "-999999999999991983.819586044000000000", "false"},
            {27, 9, "-74709851771807484.474697119", 38, 18, "-74709851771807484.474697119000000000", "false"},
            {27, 9, "332140697965026838.804669016", 38, 18, "332140697965026838.804669016000000000", "false"},
            {27, 9, "-999999799899548314.008619000", 38, 18, "-999999799899548314.008619000000000000", "false"},
            {27, 9, "853622024828283237.601866158", 38, 18, "853622024828283237.601866158000000000", "false"},
            {27, 9, "-999999999999999999.999999995", 38, 18, "-999999999999999999.999999995000000000", "false"},
            {27, 9, "839537841038657406.333967934", 38, 18, "839537841038657406.333967934000000000", "false"},
            {27, 9, "45094832001524251.270557690", 38, 18, "45094832001524251.270557690000000000", "false"},
            {27, 9, "905148844768683035.045015752", 38, 18, "905148844768683035.045015752000000000", "false"},
            {27, 9, "-739889156384067176.557026984", 38, 18, "-739889156384067176.557026984000000000", "false"},
            {27, 9, "97239583266960.946800357", 38, 18, "97239583266960.946800357000000000", "false"},
            {27, 9, "-227638992216447188.377408876", 38, 18, "-227638992216447188.377408876000000000", "false"},
            {27, 9, "48599.090161903", 38, 18, "48599.090161903000000000", "false"},
            {27, 9, "-250115297437071771.001359767", 38, 18, "-250115297437071771.001359767000000000", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL128>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal128p35s30Abnormal) {
    CastTestCaseArray test_cases = {{27, 9, "-999999999999424060.179132175", 35, 30, "", "true"},
                                    {27, 9, "96278106024514581.613329057", 35, 30, "", "true"},
                                    {27, 9, "-999999999999999992.145650484", 35, 30, "", "true"},
                                    {27, 9, "-460220645194166105.538029374", 35, 30, "", "true"},
                                    {27, 9, "-235809502759795240.544638188", 35, 30, "", "true"},
                                    {27, 9, "2177481060.483137818", 35, 30, "", "true"},
                                    {27, 9, "-999999857360157023.199506778", 35, 30, "", "true"},
                                    {27, 9, "-999999999999999991.798860679", 35, 30, "", "true"},
                                    {27, 9, "-999999999609001842.001761248", 35, 30, "", "true"},
                                    {27, 9, "688020999500633510.501504042", 35, 30, "", "true"},
                                    {27, 9, "-942302837462325603.490974513", 35, 30, "", "true"},
                                    {27, 9, "-961932305551293180.576279015", 35, 30, "", "true"},
                                    {27, 9, "276720408227771903.655272147", 35, 30, "", "true"},
                                    {27, 9, "615973715486915924.480975795", 35, 30, "", "true"},
                                    {27, 9, "-999999999999999955.636610602", 35, 30, "", "true"},
                                    {27, 9, "-999999999999999998.514990601", 35, 30, "", "true"}};
    test_cast_all_fail<TYPE_DECIMALV2, TYPE_DECIMAL128>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimalv2ToDecimal128p35s30Normal) {
    CastTestCaseArray test_cases = {
            {27, 9, "81817.236874799", 35, 30, "81817.236874799000000000000000000000", "false"},
            {27, 9, "9.59E-7", 35, 30, "0.000000959000000000000000000000", "false"},
            {27, 9, "0.810787038", 35, 30, "0.810787038000000000000000000000", "false"},
            {27, 9, "150886.376030385", 35, 30, "150886.376030385000000000000000000000", "false"}};
    test_cast_all<TYPE_DECIMALV2, TYPE_DECIMAL128>(test_cases);
}
PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal32p9s0ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{9, 0, "811615893", 27, 9, "811615893.000000000", "false"},
                                    {9, 0, "-323255728", 27, 9, "-323255728.000000000", "false"},
                                    {9, 0, "-104577237", 27, 9, "-104577237.000000000", "false"},
                                    {9, 0, "747409658", 27, 9, "747409658.000000000", "false"},
                                    {9, 0, "-278140606", 27, 9, "-278140606.000000000", "false"},
                                    {9, 0, "10601534", 27, 9, "10601534.000000000", "false"},
                                    {9, 0, "-170638669", 27, 9, "-170638669.000000000", "false"},
                                    {9, 0, "-651839886", 27, 9, "-651839886.000000000", "false"},
                                    {9, 0, "-465810182", 27, 9, "-465810182.000000000", "false"},
                                    {9, 0, "427826892", 27, 9, "427826892.000000000", "false"},
                                    {9, 0, "-999915703", 27, 9, "-999915703.000000000", "false"},
                                    {9, 0, "257821848", 27, 9, "257821848.000000000", "false"},
                                    {9, 0, "-999999514", 27, 9, "-999999514.000000000", "false"},
                                    {9, 0, "978229764", 27, 9, "978229764.000000000", "false"},
                                    {9, 0, "187350628", 27, 9, "187350628.000000000", "false"},
                                    {9, 0, "-818175193", 27, 9, "-818175193.000000000", "false"},
                                    {9, 0, "760297548", 27, 9, "760297548.000000000", "false"},
                                    {9, 0, "-218491672", 27, 9, "-218491672.000000000", "false"},
                                    {9, 0, "270914543", 27, 9, "270914543.000000000", "false"},
                                    {9, 0, "362473410", 27, 9, "362473410.000000000", "false"}};
    test_cast_all<TYPE_DECIMAL32, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal32p9s2ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{9, 2, "-8616383.73", 27, 9, "-8616383.730000000", "false"},
                                    {9, 2, "2828062.03", 27, 9, "2828062.030000000", "false"},
                                    {9, 2, "-8010810.52", 27, 9, "-8010810.520000000", "false"},
                                    {9, 2, "-4172091.41", 27, 9, "-4172091.410000000", "false"},
                                    {9, 2, "-9999999.98", 27, 9, "-9999999.980000000", "false"},
                                    {9, 2, "7068481.98", 27, 9, "7068481.980000000", "false"},
                                    {9, 2, "9203671.91", 27, 9, "9203671.910000000", "false"},
                                    {9, 2, "-9999457.08", 27, 9, "-9999457.080000000", "false"},
                                    {9, 2, "4196839.57", 27, 9, "4196839.570000000", "false"},
                                    {9, 2, "-9635310.40", 27, 9, "-9635310.400000000", "false"},
                                    {9, 2, "-2256366.45", 27, 9, "-2256366.450000000", "false"},
                                    {9, 2, "8771339.34", 27, 9, "8771339.340000000", "false"},
                                    {9, 2, "2909366.89", 27, 9, "2909366.890000000", "false"},
                                    {9, 2, "-7334183.01", 27, 9, "-7334183.010000000", "false"},
                                    {9, 2, "-6735490.34", 27, 9, "-6735490.340000000", "false"},
                                    {9, 2, "8063440.82", 27, 9, "8063440.820000000", "false"},
                                    {9, 2, "-9999912.48", 27, 9, "-9999912.480000000", "false"},
                                    {9, 2, "0.01", 27, 9, "0.010000000", "false"},
                                    {9, 2, "1716151.33", 27, 9, "1716151.330000000", "false"},
                                    {9, 2, "-9999997.44", 27, 9, "-9999997.440000000", "false"}};
    test_cast_all<TYPE_DECIMAL32, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal32p9s9ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{9, 9, "0.470294152", 27, 9, "0.470294152", "false"},
                                    {9, 9, "0.382565273", 27, 9, "0.382565273", "false"},
                                    {9, 9, "0.000001814", 27, 9, "0.000001814", "false"},
                                    {9, 9, "1E-9", 27, 9, "1E-9", "false"},
                                    {9, 9, "0.309948211", 27, 9, "0.309948211", "false"},
                                    {9, 9, "0.385095421", 27, 9, "0.385095421", "false"},
                                    {9, 9, "-0.288278642", 27, 9, "-0.288278642", "false"},
                                    {9, 9, "-0.712308569", 27, 9, "-0.712308569", "false"},
                                    {9, 9, "0.815409722", 27, 9, "0.815409722", "false"},
                                    {9, 9, "-0.787023971", 27, 9, "-0.787023971", "false"},
                                    {9, 9, "0.886985007", 27, 9, "0.886985007", "false"},
                                    {9, 9, "-0.614029444", 27, 9, "-0.614029444", "false"},
                                    {9, 9, "0.181824805", 27, 9, "0.181824805", "false"},
                                    {9, 9, "0.533520927", 27, 9, "0.533520927", "false"},
                                    {9, 9, "-0.520356392", 27, 9, "-0.520356392", "false"},
                                    {9, 9, "-0.999896130", 27, 9, "-0.999896130", "false"},
                                    {9, 9, "0.117094619", 27, 9, "0.117094619", "false"},
                                    {9, 9, "-0.697879819", 27, 9, "-0.697879819", "false"},
                                    {9, 9, "0.929172251", 27, 9, "0.929172251", "false"},
                                    {9, 9, "-0.999999998", 27, 9, "-0.999999998", "false"}};
    test_cast_all<TYPE_DECIMAL32, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal32p7s4ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{7, 4, "616.9801", 27, 9, "616.980100000", "false"},
                                    {7, 4, "-682.1476", 27, 9, "-682.147600000", "false"},
                                    {7, 4, "867.6850", 27, 9, "867.685000000", "false"},
                                    {7, 4, "-986.2924", 27, 9, "-986.292400000", "false"},
                                    {7, 4, "-501.8941", 27, 9, "-501.894100000", "false"},
                                    {7, 4, "46.8976", 27, 9, "46.897600000", "false"},
                                    {7, 4, "-46.5069", 27, 9, "-46.506900000", "false"},
                                    {7, 4, "-738.5908", 27, 9, "-738.590800000", "false"},
                                    {7, 4, "296.8268", 27, 9, "296.826800000", "false"},
                                    {7, 4, "-830.0235", 27, 9, "-830.023500000", "false"},
                                    {7, 4, "-934.1788", 27, 9, "-934.178800000", "false"},
                                    {7, 4, "714.0454", 27, 9, "714.045400000", "false"},
                                    {7, 4, "-649.7109", 27, 9, "-649.710900000", "false"},
                                    {7, 4, "0.6867", 27, 9, "0.686700000", "false"},
                                    {7, 4, "268.8630", 27, 9, "268.863000000", "false"},
                                    {7, 4, "-911.1595", 27, 9, "-911.159500000", "false"},
                                    {7, 4, "-145.9996", 27, 9, "-145.999600000", "false"},
                                    {7, 4, "-547.9996", 27, 9, "-547.999600000", "false"},
                                    {7, 4, "-746.3245", 27, 9, "-746.324500000", "false"},
                                    {7, 4, "620.2325", 27, 9, "620.232500000", "false"}};
    test_cast_all<TYPE_DECIMAL32, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal64p18s0ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{18, 0, "-551746063335610232", 27, 9, "-551746063335610232.000000000", "false"},
                                    {18, 0, "-448777412535093959", 27, 9, "-448777412535093959.000000000", "false"},
                                    {18, 0, "-999999999999999705", 27, 9, "-999999999999999705.000000000", "false"},
                                    {18, 0, "-982492492819642853", 27, 9, "-982492492819642853.000000000", "false"},
                                    {18, 0, "-97451123464181067", 27, 9, "-97451123464181067.000000000", "false"},
                                    {18, 0, "952951482202010503", 27, 9, "952951482202010503.000000000", "false"},
                                    {18, 0, "236539896229665", 27, 9, "236539896229665.000000000", "false"},
                                    {18, 0, "159759796847252755", 27, 9, "159759796847252755.000000000", "false"},
                                    {18, 0, "-12039679474883885", 27, 9, "-12039679474883885.000000000", "false"},
                                    {18, 0, "-999999999999998621", 27, 9, "-999999999999998621.000000000", "false"},
                                    {18, 0, "-861289108885435474", 27, 9, "-861289108885435474.000000000", "false"},
                                    {18, 0, "-319420214804923411", 27, 9, "-319420214804923411.000000000", "false"},
                                    {18, 0, "756190457835207720", 27, 9, "756190457835207720.000000000", "false"},
                                    {18, 0, "-999996715703707755", 27, 9, "-999996715703707755.000000000", "false"},
                                    {18, 0, "-768147170902226177", 27, 9, "-768147170902226177.000000000", "false"},
                                    {18, 0, "-661017643809888664", 27, 9, "-661017643809888664.000000000", "false"},
                                    {18, 0, "460528266062681187", 27, 9, "460528266062681187.000000000", "false"},
                                    {18, 0, "370416845998030718", 27, 9, "370416845998030718.000000000", "false"},
                                    {18, 0, "-984358851321309545", 27, 9, "-984358851321309545.000000000", "false"},
                                    {18, 0, "471765828305914253", 27, 9, "471765828305914253.000000000", "false"}};
    test_cast_all<TYPE_DECIMAL64, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal64p18s2ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{18, 2, "-9999937796831492.54", 27, 9, "-9999937796831492.540000000", "false"},
                                    {18, 2, "1010917844915429.58", 27, 9, "1010917844915429.580000000", "false"},
                                    {18, 2, "5516328936649137.28", 27, 9, "5516328936649137.280000000", "false"},
                                    {18, 2, "-8394773120557002.39", 27, 9, "-8394773120557002.390000000", "false"},
                                    {18, 2, "-8586254176919204.96", 27, 9, "-8586254176919204.960000000", "false"},
                                    {18, 2, "-9999999999998736.85", 27, 9, "-9999999999998736.850000000", "false"},
                                    {18, 2, "5895483844446178.94", 27, 9, "5895483844446178.940000000", "false"},
                                    {18, 2, "-9105655774087591.92", 27, 9, "-9105655774087591.920000000", "false"},
                                    {18, 2, "-9999999871300967.58", 27, 9, "-9999999871300967.580000000", "false"},
                                    {18, 2, "-9999999999998020.20", 27, 9, "-9999999999998020.200000000", "false"},
                                    {18, 2, "-3094253090466262.20", 27, 9, "-3094253090466262.200000000", "false"},
                                    {18, 2, "-9999999999999998.39", 27, 9, "-9999999999999998.390000000", "false"},
                                    {18, 2, "-4471237086867172.49", 27, 9, "-4471237086867172.490000000", "false"},
                                    {18, 2, "-9999999999999999.98", 27, 9, "-9999999999999999.980000000", "false"},
                                    {18, 2, "-3188348008836351.70", 27, 9, "-3188348008836351.700000000", "false"},
                                    {18, 2, "697981868824929.48", 27, 9, "697981868824929.480000000", "false"},
                                    {18, 2, "0.01", 27, 9, "0.010000000", "false"},
                                    {18, 2, "9710238880354059.52", 27, 9, "9710238880354059.520000000", "false"},
                                    {18, 2, "4736215455534.69", 27, 9, "4736215455534.690000000", "false"},
                                    {18, 2, "-5402461726883681.78", 27, 9, "-5402461726883681.780000000", "false"}};
    test_cast_all<TYPE_DECIMAL64, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal64p18s9ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{18, 9, "-204987486.864872908", 27, 9, "-204987486.864872908", "false"},
                                    {18, 9, "556000053.500167995", 27, 9, "556000053.500167995", "false"},
                                    {18, 9, "-913563688.838804153", 27, 9, "-913563688.838804153", "false"},
                                    {18, 9, "503794069.798234472", 27, 9, "503794069.798234472", "false"},
                                    {18, 9, "394310798.756854347", 27, 9, "394310798.756854347", "false"},
                                    {18, 9, "-999999987.630320024", 27, 9, "-999999987.630320024", "false"},
                                    {18, 9, "296934088.811053262", 27, 9, "296934088.811053262", "false"},
                                    {18, 9, "85059252.757551189", 27, 9, "85059252.757551189", "false"},
                                    {18, 9, "561456905.632761757", 27, 9, "561456905.632761757", "false"},
                                    {18, 9, "-47816529.609278099", 27, 9, "-47816529.609278099", "false"},
                                    {18, 9, "2E-9", 27, 9, "2E-9", "false"},
                                    {18, 9, "-999999999.999882035", 27, 9, "-999999999.999882035", "false"},
                                    {18, 9, "369690966.472272308", 27, 9, "369690966.472272308", "false"},
                                    {18, 9, "-691935315.757546353", 27, 9, "-691935315.757546353", "false"},
                                    {18, 9, "-178615711.909143763", 27, 9, "-178615711.909143763", "false"},
                                    {18, 9, "-999984682.074056422", 27, 9, "-999984682.074056422", "false"},
                                    {18, 9, "-99621571.947488855", 27, 9, "-99621571.947488855", "false"},
                                    {18, 9, "-156296516.852688463", 27, 9, "-156296516.852688463", "false"},
                                    {18, 9, "9E-9", 27, 9, "9E-9", "false"},
                                    {18, 9, "0.000282589", 27, 9, "0.000282589", "false"}};
    test_cast_all<TYPE_DECIMAL64, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal64p18s18ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{18, 18, "-0.762486818710993687", 27, 9, "-0.762486819", "false"},
                                    {18, 18, "-0.323134962510917619", 27, 9, "-0.323134963", "false"},
                                    {18, 18, "-0.206429520611345170", 27, 9, "-0.206429521", "false"},
                                    {18, 18, "-0.999999031394798780", 27, 9, "-0.999999031", "false"},
                                    {18, 18, "0.697668409747765712", 27, 9, "0.697668410", "false"},
                                    {18, 18, "-0.999999994286574494", 27, 9, "-0.999999994", "false"},
                                    {18, 18, "-0.239696089078967100", 27, 9, "-0.239696089", "false"},
                                    {18, 18, "0.089638820853252968", 27, 9, "0.089638821", "false"},
                                    {18, 18, "-0.999999999504041575", 27, 9, "-1.000000000", "false"},
                                    {18, 18, "-0.999999991518324767", 27, 9, "-0.999999992", "false"},
                                    {18, 18, "0.048485141366725298", 27, 9, "0.048485141", "false"},
                                    {18, 18, "0.000686924417213258", 27, 9, "0.000686924", "false"},
                                    {18, 18, "-0.999999999999968650", 27, 9, "-1.000000000", "false"},
                                    {18, 18, "-0.995995404980326636", 27, 9, "-0.995995405", "false"},
                                    {18, 18, "-0.282253921180042940", 27, 9, "-0.282253921", "false"},
                                    {18, 18, "-0.999999999999999936", 27, 9, "-1.000000000", "false"},
                                    {18, 18, "0.380131273307672679", 27, 9, "0.380131273", "false"},
                                    {18, 18, "-0.968043305861812213", 27, 9, "-0.968043306", "false"},
                                    {18, 18, "-0.999999888112931570", 27, 9, "-0.999999888", "false"},
                                    {18, 18, "6.13962805055E-7", 27, 9, "6.14E-7", "false"}};
    test_cast_all<TYPE_DECIMAL64, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal64p15s13ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {{15, 13, "-99.9999898235029", 27, 9, "-99.999989824", "false"},
                                    {15, 13, "-73.2283471196913", 27, 9, "-73.228347120", "false"},
                                    {15, 13, "-99.9999999940118", 27, 9, "-99.999999994", "false"},
                                    {15, 13, "-99.9981614675970", 27, 9, "-99.998161468", "false"},
                                    {15, 13, "17.8183575065977", 27, 9, "17.818357507", "false"},
                                    {15, 13, "78.8297611044740", 27, 9, "78.829761104", "false"},
                                    {15, 13, "89.3014688556604", 27, 9, "89.301468856", "false"},
                                    {15, 13, "-53.6048364218292", 27, 9, "-53.604836422", "false"},
                                    {15, 13, "14.6075691818520", 27, 9, "14.607569182", "false"},
                                    {15, 13, "-97.0080505056389", 27, 9, "-97.008050506", "false"},
                                    {15, 13, "0.0004081071233", 27, 9, "0.000408107", "false"},
                                    {15, 13, "-99.9999905273850", 27, 9, "-99.999990527", "false"},
                                    {15, 13, "-54.5443180476860", 27, 9, "-54.544318048", "false"},
                                    {15, 13, "-82.2011288769123", 27, 9, "-82.201128877", "false"},
                                    {15, 13, "-93.6480383142509", 27, 9, "-93.648038314", "false"},
                                    {15, 13, "-65.4667562482115", 27, 9, "-65.466756248", "false"},
                                    {15, 13, "93.0599858076311", 27, 9, "93.059985808", "false"},
                                    {15, 13, "0.0000510911712", 27, 9, "0.000051091", "false"},
                                    {15, 13, "4.606002E-7", 27, 9, "4.61E-7", "false"},
                                    {15, 13, "-40.4970110664971", 27, 9, "-40.497011066", "false"}};
    test_cast_all<TYPE_DECIMAL64, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p38s0ToDecimalv2Abnormal) {
    CastTestCaseArray test_cases = {{38, 0, "-99999999999999999999973896415843170930", 27, 9, "", "true"},
                                    {38, 0, "44311337834270963058885289819992369332", 27, 9, "", "true"},
                                    {38, 0, "-99999999999999999999771439767328194224", 27, 9, "", "true"},
                                    {38, 0, "-99999999999999999977527508989860514603", 27, 9, "", "true"},
                                    {38, 0, "-99999999477283824770622345037144543006", 27, 9, "", "true"},
                                    {38, 0, "-99999999999999998785185709291846051846", 27, 9, "", "true"},
                                    {38, 0, "-99999999999999999999999992393277967686", 27, 9, "", "true"},
                                    {38, 0, "-99999999999999999999997770564030792415", 27, 9, "", "true"},
                                    {38, 0, "-99996523346047019286783449249314476505", 27, 9, "", "true"},
                                    {38, 0, "-99999976651743346940791444828746611883", 27, 9, "", "true"},
                                    {38, 0, "-99963829982106750622596535611417190470", 27, 9, "", "true"}};
    test_cast_all_fail<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p38s0ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {
            {38, 0, "0", 27, 9, "0E-9", "false"},
            {38, 0, "439643530720079807046288", 27, 9, "439643530720079807046288.000000000", "false"},
            {38, 0, "64177773135", 27, 9, "64177773135.000000000", "false"},
            {38, 0, "14152430", 27, 9, "14152430.000000000", "false"},
            {38, 0, "185429159154185", 27, 9, "185429159154185.000000000", "false"},
            {38, 0, "40107", 27, 9, "40107.000000000", "false"},
            {38, 0, "35693072148104634", 27, 9, "35693072148104634.000000000", "false"},
            {38, 0, "730", 27, 9, "730.000000000", "false"},
            {38, 0, "7170898687891214856985", 27, 9, "7170898687891214856985.000000000", "false"}};
    test_cast_all<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p38s2ToDecimalv2Abnormal) {
    CastTestCaseArray test_cases = {{38, 2, "-999999999999999999999999999999998268.89", 27, 9, "", "true"},
                                    {38, 2, "-999999999477314564388785053565819081.44", 27, 9, "", "true"},
                                    {38, 2, "-999971680880788613936112593096853659.61", 27, 9, "", "true"},
                                    {38, 2, "-999999999999999999999999999999985952.28", 27, 9, "", "true"},
                                    {38, 2, "-999999990338202190703100177005181833.21", 27, 9, "", "true"},
                                    {38, 2, "-999999999728954428473118435539515578.15", 27, 9, "", "true"},
                                    {38, 2, "-784810461506478692187803891410079584.84", 27, 9, "", "true"},
                                    {38, 2, "-999999999999999999999999999999997569.42", 27, 9, "", "true"},
                                    {38, 2, "-999999999999994306266125560405977349.62", 27, 9, "", "true"},
                                    {38, 2, "-999999999999999999999999999870612573.94", 27, 9, "", "true"},
                                    {38, 2, "-999999999999999935315642530991300038.09", 27, 9, "", "true"},
                                    {38, 2, "-999999999999999999999999983536939998.81", 27, 9, "", "true"}};
    test_cast_all_fail<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p38s2ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {
            {38, 2, "8296.98", 27, 9, "8296.980000000", "false"},
            {38, 2, "53183009810645919.86", 27, 9, "53183009810645919.860000000", "false"},
            {38, 2, "10074690616512.11", 27, 9, "10074690616512.110000000", "false"},
            {38, 2, "0.04", 27, 9, "0.040000000", "false"},
            {38, 2, "101219527969852.95", 27, 9, "101219527969852.950000000", "false"},
            {38, 2, "6788401871.20", 27, 9, "6788401871.200000000", "false"},
            {38, 2, "58869164.29", 27, 9, "58869164.290000000", "false"},
            {38, 2, "731909414467278252509253.07", 27, 9, "731909414467278252509253.070000000", "false"}};
    test_cast_all<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p38s9ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {
            {38, 9, "-99999999924216394604840345052.859664367", 27, 9, "-99999999924216394604840345052.859664367",
             "false"},
            {38, 9, "-99999999999999999889600302199.889295329", 27, 9, "-99999999999999999889600302199.889295329",
             "false"},
            {38, 9, "-99979713870377929045203809857.459798631", 27, 9, "-99979713870377929045203809857.459798631",
             "false"},
            {38, 9, "0.000024332", 27, 9, "0.000024332", "false"},
            {38, 9, "-99999999999999999999999999999.999296102", 27, 9, "-99999999999999999999999999999.999296102",
             "false"},
            {38, 9, "-99999999999999999999999999999.999702653", 27, 9, "-99999999999999999999999999999.999702653",
             "false"},
            {38, 9, "-99999999895560801636009625466.401115442", 27, 9, "-99999999895560801636009625466.401115442",
             "false"},
            {38, 9, "31192180055.954793317", 27, 9, "31192180055.954793317", "false"},
            {38, 9, "3619218033671469.535173414", 27, 9, "3619218033671469.535173414", "false"},
            {38, 9, "0.000001907", 27, 9, "0.000001907", "false"},
            {38, 9, "642145667259440981541872.676614761", 27, 9, "642145667259440981541872.676614761", "false"},
            {38, 9, "0.000172419", 27, 9, "0.000172419", "false"},
            {38, 9, "-99999999999999999999992123256.343072144", 27, 9, "-99999999999999999999992123256.343072144",
             "false"},
            {38, 9, "302014889.642541586", 27, 9, "302014889.642541586", "false"},
            {38, 9, "0.000028794", 27, 9, "0.000028794", "false"},
            {38, 9, "-99999999999999999999999999999.981625624", 27, 9, "-99999999999999999999999999999.981625624",
             "false"},
            {38, 9, "3.1E-8", 27, 9, "3.1E-8", "false"},
            {38, 9, "166.435409058", 27, 9, "166.435409058", "false"},
            {38, 9, "434787297.810474121", 27, 9, "434787297.810474121", "false"},
            {38, 9, "12963208099927757292428.103424893", 27, 9, "12963208099927757292428.103424893", "false"}};
    test_cast_all<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p38s13ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {
            {38, 13, "-9998171834185573471872115.9863130326500", 27, 9, "-9998171834185573471872115.986313033",
             "false"},
            {38, 13, "14999145542535925657.8156699748733", 27, 9, "14999145542535925657.815669975", "false"},
            {38, 13, "3E-13", 27, 9, "0E-9", "false"},
            {38, 13, "6946069087410808830534.4248342692648", 27, 9, "6946069087410808830534.424834269", "false"},
            {38, 13, "2820.4711079132168", 27, 9, "2820.471107913", "false"},
            {38, 13, "-9991545285457008791223368.2680668340372", 27, 9, "-9991545285457008791223368.268066834",
             "false"},
            {38, 13, "3.798566E-7", 27, 9, "3.80E-7", "false"},
            {38, 13, "-9998166024237494796323424.4512670303620", 27, 9, "-9998166024237494796323424.451267030",
             "false"},
            {38, 13, "-9999999999999999999981498.5779448324875", 27, 9, "-9999999999999999999981498.577944832",
             "false"},
            {38, 13, "-9999999999999999999999999.9932144131433", 27, 9, "-9999999999999999999999999.993214413",
             "false"},
            {38, 13, "154848.0730675236151", 27, 9, "154848.073067524", "false"},
            {38, 13, "-9999884477491641663109191.0547269475774", 27, 9, "-9999884477491641663109191.054726948",
             "false"},
            {38, 13, "124028551196935459163.7220314937047", 27, 9, "124028551196935459163.722031494", "false"},
            {38, 13, "-9998633630439480686360626.9611542121242", 27, 9, "-9998633630439480686360626.961154212",
             "false"},
            {38, 13, "31199409550567475299.2893155611141", 27, 9, "31199409550567475299.289315561", "false"},
            {38, 13, "-9999996073869518485908022.7683268900041", 27, 9, "-9999996073869518485908022.768326890",
             "false"},
            {38, 13, "-9999999999999999999999654.9195299469182", 27, 9, "-9999999999999999999999654.919529947",
             "false"},
            {38, 13, "0.0018314517377", 27, 9, "0.001831452", "false"},
            {38, 13, "-9999452336913951642366777.8887833652616", 27, 9, "-9999452336913951642366777.888783365",
             "false"},
            {38, 13, "-9999999999999999999999999.9999052941003", 27, 9, "-9999999999999999999999999.999905294",
             "false"}};
    test_cast_all<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p38s18ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {
            {38, 18, "-99999999794114130603.891439218809040983", 27, 9, "-99999999794114130603.891439219", "false"},
            {38, 18, "519055250449595530.591732025777232573", 27, 9, "519055250449595530.591732026", "false"},
            {38, 18, "-99999999849093024560.812745431261941583", 27, 9, "-99999999849093024560.812745431", "false"},
            {38, 18, "0.002746590043933196", 27, 9, "0.002746590", "false"},
            {38, 18, "0.002498928328685434", 27, 9, "0.002498928", "false"},
            {38, 18, "-99999999999999999999.998183744169415151", 27, 9, "-99999999999999999999.998183744", "false"},
            {38, 18, "1513553.737075384844376548", 27, 9, "1513553.737075385", "false"},
            {38, 18, "319698606305645435.865999865375876763", 27, 9, "319698606305645435.865999865", "false"},
            {38, 18, "-99999999999999999999.996233071308760470", 27, 9, "-99999999999999999999.996233071", "false"},
            {38, 18, "-99999999807202768288.562415424436416800", 27, 9, "-99999999807202768288.562415424", "false"},
            {38, 18, "-99999999999999999696.086472212375606529", 27, 9, "-99999999999999999696.086472212", "false"},
            {38, 18, "7.2E-17", 27, 9, "0E-9", "false"},
            {38, 18, "1.98802331178E-7", 27, 9, "1.99E-7", "false"},
            {38, 18, "1.989061531E-9", 27, 9, "2E-9", "false"},
            {38, 18, "-99999999999999999999.999999999996440309", 27, 9, "-100000000000000000000.000000000", "false"},
            {38, 18, "1.0864929E-11", 27, 9, "0E-9", "false"},
            {38, 18, "-99999999999999999999.999998037596050179", 27, 9, "-99999999999999999999.999998038", "false"},
            {38, 18, "5.3009E-14", 27, 9, "0E-9", "false"},
            {38, 18, "2.09067032212E-7", 27, 9, "2.09E-7", "false"},
            {38, 18, "9.59956E-13", 27, 9, "0E-9", "false"}};
    test_cast_all<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}

PARALLEL_TEST(VectorizedDecimalCastExprDecimalV2Test, testCastFromDecimal128p35s30ToDecimalv2Normal) {
    CastTestCaseArray test_cases = {
            {35, 30, "9.48409510765057734817137E-7", 27, 9, "9.48E-7", "false"},
            {35, 30, "78605.168949071413274106330103460140", 27, 9, "78605.168949071", "false"},
            {35, 30, "-99999.999999999993956063298909509875", 27, 9, "-100000.000000000", "false"},
            {35, 30, "0.022375989129336920666453591609", 27, 9, "0.022375989", "false"},
            {35, 30, "1937.783238085999554373455300098756", 27, 9, "1937.783238086", "false"},
            {35, 30, "4.215214826112E-18", 27, 9, "0E-9", "false"},
            {35, 30, "2.7277820287464729729163E-8", 27, 9, "2.7E-8", "false"},
            {35, 30, "-99999.999918010513797667913677225849", 27, 9, "-99999.999918011", "false"},
            {35, 30, "-99999.999999999999999999999999999827", 27, 9, "-100000.000000000", "false"},
            {35, 30, "-66848.431577886204583335825730407457", 27, 9, "-66848.431577886", "false"},
            {35, 30, "-99999.999999999999999999999984250024", 27, 9, "-100000.000000000", "false"},
            {35, 30, "7.066832755212054426224E-9", 27, 9, "7E-9", "false"},
            {35, 30, "2.901E-27", 27, 9, "0E-9", "false"},
            {35, 30, "-99999.999999999999999999998516235635", 27, 9, "-100000.000000000", "false"},
            {35, 30, "4145.265991062807964562236618862812", 27, 9, "4145.265991063", "false"},
            {35, 30, "-99999.999999999999941968499468927090", 27, 9, "-100000.000000000", "false"},
            {35, 30, "-99999.999980717895793630037648565001", 27, 9, "-99999.999980718", "false"},
            {35, 30, "-99313.245150660359278165855486865300", 27, 9, "-99313.245150660", "false"},
            {35, 30, "-99999.965392354475186301316008016831", 27, 9, "-99999.965392354", "false"},
            {35, 30, "0.009418270381033562004428747944", 27, 9, "0.009418270", "false"}};
    test_cast_all<TYPE_DECIMAL128, TYPE_DECIMALV2>(test_cases);
}
} // namespace starrocks::vectorized
